package com.example.myapplication.activity;


import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.myapplication.R;

public class RentiActivity extends BaseActivity {

    @Override
    protected void doHttpData(Message message) {
        switch (message.what) {
            case GET_DEVICE_PROPERTIES:
                String string = (String) message.obj;
                Log.d("zoubo", string);
                String response = JSON.parseObject(string).getString("response");
                JSONObject properties =
                        JSON.parseObject(response).getJSONArray("services").getJSONObject(0).getJSONObject(
                                "properties");
                Log.d("zoubo", properties.toJSONString());
                setData(properties);
                //开启定时轮询（查询设备属性）
                if (myScheduleTask == null) {
                    myScheduleTask = new MyScheduleTask();
                }
                getMyHttpHandler().postDelayed(myScheduleTask, 2000);
                break;
        }
    }

    private void setData(JSONObject properties) {
        value.setText(properties.getString("Infrared_Status"));
    }

    @Override
    protected String serviceID() {
        return "Infrared";
    }

    @Override
    protected int layoutID() {
        return R.layout.activity_renti;
    }

    private TextView value;

    @Override
    protected void initView() {
        value = (TextView) findViewById(R.id.value);
    }
}